/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package manager;

import JDBCUtil.MyConn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import model.admin.Country;
import model.admin.Feedback;
import model.admin.ImageType;

/**
 *
 * @author TuanAnh
 */
public class ImageTypeManager {

    Connection conn;

    public ImageTypeManager() {
        try {
            conn = MyConn.getConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<ImageType> getAll() {
        List<ImageType> list = new ArrayList<ImageType>();
        try {
            PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM Image_Types");
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                ImageType model = new ImageType();
                model.setImage_Type_Id(rs.getInt("Image_Type_Id"));
                model.setImage_Type_Name(rs.getString("Image_Type_Name"));
                model.setImage_Type_Status(rs.getBoolean("Image_Type_Status"));
                list.add(model);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public boolean insert(ImageType f) {
        try {
            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO Image_Types (Image_Type_Status,Image_Type_Name) VALUES (?,?)");
            pstmt.setBoolean(1, f.isImage_Type_Status());
            pstmt.setString(2, f.getImage_Type_Name());
            int eu = pstmt.executeUpdate();
            if (eu > 0) {
                return true;
            }
        } catch (Exception e) {
        }
        return false;
    }

    public boolean update(ImageType f) {
        PreparedStatement pstmt;
        try {
            pstmt = conn.prepareStatement("UPDATE Image_Types SET Image_Type_Status = ? ,Image_Type_Name = ? WHERE Image_Type_Id = ?");
            pstmt.setBoolean(1, f.isImage_Type_Status());
            pstmt.setString(2, f.getImage_Type_Name());
            pstmt.setInt(3, f.getImage_Type_Id());
            int eu = pstmt.executeUpdate();
            if (eu > 0) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public boolean delete(int id) {
        try {
            PreparedStatement pstmt = conn.prepareStatement("DELETE FROM Image_Types WHERE Image_Type_Id = ?");
            pstmt.setInt(1, id);
            int eu = pstmt.executeUpdate();
            if (eu > 0) {
                return true;
            }
        } catch (Exception e) {
        }

        return false;
    }
}
